﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once

#include <map>
#include "GcmpDwgDxfInterface.h"


namespace gcmp
{

    class GCMP_DWG_DXF_INTERFACE_EXPORT IErrorCode
    {
    public:
        /// \brief 获取errorCode
        /// \return 返回errorCode
        virtual int GetCode() const = 0;

        /// \brief 获取错误的类别
        /// \return 返回错误类型
        virtual std::wstring GetErrorCategory() const = 0;

        virtual ~IErrorCode() {}
    };

    class GCMP_DWG_DXF_INTERFACE_EXPORT IError
    {
    public:
        /// \brief 初始化错误码与错误描述的映射关系
        /// 配置文件为json文件，可有多个配置文件，需要放置在指定目录下
        /// [{"ErrorCode": 0, "ErrorCategory": "dwg导入导出", "Description": "文档路径不存在"},{...}]
        static void InitErrorCodeAndDescriptionMapping(const std::wstring& configDir);
        static std::map<std::pair<int, std::wstring>, std::wstring> GetErrorCodeAndDescriptionMapping();

        /// \brief 创建默认的error
        /// \note 也可继承接口类实现自定义error
        static OwnerPtr<IError> CreateDefaultError(OwnerPtr<IErrorCode> pErrorCode, const std::wstring& errorMsg);

        /// \brief 获取errorCode
        /// \return 返回errorCode
        virtual const IErrorCode* GetErrorCode() const = 0;

        /// \brief 获取错误描述
        /// \return 返回错误描述
        virtual std::wstring GetDescription() const = 0;
    };
}
